using StackCalc.Instructions;

namespace StackCalc.Parsing.ParsingUnits
{
	public class CharacterParser : BaseParsingUnit<PushCharacter>
	{
		protected override bool CanParseImplementation(string input)
		{
			// characters can always be parsed
			return true;
		}

		protected override bool HasSyntaxErrorImplementation(string input)
		{
			// ']' can never occur as first symbol
			return input[0] == ']';
		}

		public override string GetErrorDescription()
		{
			return "'[' can never be the first input!";
		}

		protected override PushCharacter ParseImplementation(string input)
		{
			// return first character
			return new PushCharacter(input[0]);
		}

		protected override string TrunkateImplementation(string input)
		{
			return input.Remove(0, 1);
		}
	}
}
